<?php

/** 积分 月统计
 * 在 每月 第一天 统计上个月 数据
 只保存 每个用户 当前 的积分数 即可，不需要全部进行统计
 */
namespace app\Console;

use think\console\Command;

use think\console\Input;
use think\console\Output;

use think\Db;
use think\db\Query;

class PointMonthStatis extends  Command
{


    protected function configure(){
        $this->setName('pointmonthstatis:start')->setDescription('Point Month Statistics!');


    }
    protected function execute(Input $input, Output $output){

        $today = date('Ymd');
        $cur_day = new \DateTime($today);

        $date_interval = new \DateInterval('P1M');

        $dt = $cur_day->sub($date_interval);
        $month = $dt->format('Ym');
        $list =Db::name('userinfo')
            ->field('user_id,available_points+consume_points as total_points,consume_points as consume_points,'.$month.' as month')
            ->select();

        $query = new Query();
        $query->name('points_mon_statistics')
            ->insertAll($list);

    }

}